package elcs.mentoring.model;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
@Service
public class MentoringServiceImpl implements MentoringService {
   @Resource(name="mentoringDaoImpl")
   private MentoringDao mentoringDao;
   @Resource(name="noteDaoImpl")
   private NoteDao noteDao;
   
   /**
    * 자신의 레벨 보다 높은 등급의 레벨을 가져온다.
    * By SSA
    */
   @Override
   public List getMyMentorLevel(int level) throws Exception {
      return mentoringDao.getMyMentorLevel(level);
   }




   @Override
   // 수정
   public Map statusView(String id) throws Exception {
      List sendRList=mentoringDao.getSendRequestList(id);
      List receiveRList=mentoringDao.getReceiveRequestList(id);
      List<NoteVO> qlist=(List<NoteVO>)noteDao.getQuestionList(id);
      Map map=new HashMap();
      qlist=settingStatus(qlist,id);
      map.put("sendRlist", sendRList);
      map.put("receiveRList", receiveRList);
      map.put("qlist", qlist);
      return map;
   }



   @Override
   public List findStatusList(NoteVO nvo) throws Exception {
      // TODO Auto-generated method stub
      return null;
   }

   @Override
   public NoteVO viewNoteContent(int no) throws Exception {
	   return noteDao.viewNoteContent(no);
   }

   @Override
   public int deleteNote(NoteVO nvo) throws Exception {
      // TODO Auto-generated method stub
      return 0;
   }

   @Override
   public int rejectMentorQuestion(int no) throws Exception {
      // TODO Auto-generated method stub
      return 0;
   }

   @Override
   public int replyMentorQuestion(NoteVO nvo) throws Exception {
     return noteDao.replyMentorQuestion(nvo);
   }

   @Override
   public List getNoteList(MentoringVO mentoVO) throws Exception {
      // TODO Auto-generated method stub
      return null;
   }

   @Override
   public List findNoteList(NoteVO nvo) throws Exception {
      // TODO Auto-generated method stub
      return null;
   }

   @Override
   public int sendNote(NoteVO nvo) throws Exception {
      // TODO Auto-generated method stub
      return 0;
   }

   @Override
   public int replyNote(NoteVO nvo) throws Exception {
      // TODO Auto-generated method stub
      return 0;
   }

   @Override
   public List getRequestList(String id) throws Exception {
      // TODO Auto-generated method stub
      return null;
   }

   @Override
   public int sendMentorRequest(MentoringVO mentoVO) throws Exception {
      // TODO Auto-generated method stub
      return 0;
   }

   @Override
   public int replyMentorRequest(MentoringVO mentoVO) throws Exception {
      // TODO Auto-generated method stub
      return 0;
   }

   @Override
   public List getMyMentorList(String id) throws Exception {
      // TODO Auto-generated method stub
      return null;
   }

   @Override
   public List getMyMenteeList(String id) throws Exception {
      // TODO Auto-generated method stub
      return null;
   }

   private List<NoteVO> settingStatus(List<NoteVO> qlist,String id) {
      for(NoteVO nvo:qlist){
         if(nvo.getSender().getId().equals(id)){//내가 보낸 질문
            if(nvo.getRefOrder()==3&&nvo.getReject()==-1){
               nvo.setStatus("보낸질문(거절됨)");
            }else if(nvo.getReject()==1){
               nvo.setStatus("보낸질문(답변완료)");
            }else {
               nvo.setStatus("보낸질문(대기중)");
            }
         }else if(nvo.getReceiver().getId().equals(id)){
            if(nvo.getReject()==0){
               if(nvo.getReNoteNo()==-1)
                  nvo.setStatus("받은질문(대기중)");
               else
                  nvo.setStatus("답변");
            }else    if(nvo.getReject()==1){
               nvo.setStatus("받은질문(답변완료)");
            }else{
               nvo.setStatus("받은질문(거절함)");
            }
         }
         System.out.println(nvo);
      }
      return qlist;
   }
   
   /**
    * 멘토 레벨 선택 시  자신의 레벨과 비교하여 
    * 소모되는 포인트를 계산하여 보여준다.
    * By SSA
    */
   @Override
   public int getPointForRequest(Map map) throws Exception {

      return noteDao.getPointForRequest(map);
   }
   /**
    * 선택한 레벨의 멘토에게 질문 제목과 내용을 전송한다.
    * 레벨 차이만큼 포인트가 감소된다.
    * BY SSA
    */
   @Override
   public int sendMentorQuestion(NoteVO nvo) throws Exception {
      return noteDao.sendMentorQuestion(nvo);
   }

}